home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue63 / Construc / CUnit.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-10-04  |  1.7 KB  |  76 lines

  1. unit CUnit;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  5.   Db, ExtCtrls, DBCtrls, Grids, DBGrids, DBClient, ScktComp, StdCtrls;
  6.  
  7. type
  8.   TForm2 = class(TForm)
  9.     ClientSocket1: TClientSocket;
  10.     ClientDataSet1: TClientDataSet;
  11.     DBGrid1: TDBGrid;
  12.     DBNavigator1: TDBNavigator;
  13.     DataSource1: TDataSource;
  14.     Button1: TButton;
  15.     Button2: TButton;
  16.     procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
  17.     procedure Button1Click(Sender: TObject);
  18.     procedure Button2Click(Sender: TObject);
  19.     procedure FormActivate(Sender: TObject);
  20.   private
  21.     { Private declarations }
  22.     SocketText: String;
  23.   public
  24.     { Public declarations }
  25.   end;
  26.  
  27. var
  28.   Form2: TForm2;
  29.  
  30. implementation
  31.  
  32. {$R *.DFM}
  33.  
  34. procedure TForm2.FormActivate(Sender: TObject);
  35. begin
  36.   SocketText := '';
  37. end;
  38.  
  39. procedure TForm2.ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
  40. var
  41.   F: System.Text;
  42. begin
  43.   Caption := Caption + '.';
  44.   SocketText := SocketText + Socket.ReceiveText;
  45.   if Pos('</DATAPACKET>',SocketText) > 0 then
  46.   begin
  47.     System.Assign(F,'client.xml');
  48.     Rewrite(F);
  49.     writeln(F,SocketText);
  50.     System.Close(F);
  51.     Caption := Caption + '!';
  52.     SocketText := ''
  53.   end
  54. end;
  55.  
  56. procedure TForm2.Button1Click(Sender: TObject);
  57. begin
  58.   if (Sender AS TButton).Caption = 'Connect' then
  59.   begin
  60.     (Sender AS TButton).Caption := 'Disconnect';
  61.     ClientSocket1.Active := True
  62.   end
  63.   else
  64.   begin
  65.     (Sender AS TButton).Caption := 'Connect';
  66.     ClientSocket1.Active := False
  67.   end
  68. end;
  69.  
  70. procedure TForm2.Button2Click(Sender: TObject);
  71. begin
  72.   ClientDataSet1.LoadFromFile('client.xml');
  73. end;
  74.  
  75. end.
  76.